package com.shtel.paas.monitorcenter.miroservice.management.service.impl;

import com.github.pagehelper.PageHelper;
import com.shtel.paas.monitorcenter.asset.management.entity.HostListEntity;
import com.shtel.paas.monitorcenter.miroservice.management.entity.MiroServiceEntity;
import com.shtel.paas.monitorcenter.miroservice.management.mapper.MiroServiceListMapper;
import com.shtel.paas.monitorcenter.miroservice.management.service.MiroServiceDataService;
import com.shtel.paas.monitorcenter.util.Page;
import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.sql.SQLException;
import java.util.Iterator;
import java.util.LinkedList;
import java.util.List;

/**
 * @ClassName
 * @Description Too
 * @Author ME
 * @Data 2018/07/18 15:56
 **/
@Service
public class MiroServiceDataServiceImpl implements MiroServiceDataService {
    @Autowired
    private  MiroServiceListMapper mapper;

    @Override
    public Page<MiroServiceEntity> selectMicroServiceInfo(String miroservice,int page,int size) {
        PageHelper.startPage(page, size);
        List<MiroServiceEntity> miroServiceEntities = null;
        try {
            if(StringUtils.isBlank(miroservice)){
                miroServiceEntities = mapper.selectMiroservice();

            }else{
                MiroServiceEntity miroServiceEntity = new MiroServiceEntity();
                miroServiceEntity.setMiroservice(miroservice);
                 miroServiceEntities = mapper.selectMiroservice(miroServiceEntity);

            }
        } catch (SQLException e) {
            e.printStackTrace();
        }

        Page<MiroServiceEntity> pageContent = Page.build(miroServiceEntities);
        return pageContent;
    }

    @Override
    public int insertMicroServiceInfo(MiroServiceEntity miroServiceEntity) {
        int dao=0;
        try {
            dao= mapper.insertMiroservice(miroServiceEntity);
        } catch (SQLException e) {
            e.printStackTrace();
        }
        return dao;
    }

    @Override
    public int updateMicroServiceInfo(MiroServiceEntity miroServiceEntity) {
        int dao = 0;
        try {
            dao= mapper.updateMiroservice(miroServiceEntity);
        } catch (SQLException e) {
            e.printStackTrace();
        }
        return dao;
    }

    @Override
    public int deleteMicroServiceInfo(MiroServiceEntity miroServiceEntity) {
        int dao=0;
        try {

            dao=mapper.deleteMiroservice(miroServiceEntity.getPodName());
//            List<MiroServiceEntity> miroServiceEntities = mapper.selectMiroserviceList(miroServiceEntity);//查询该数据是否存在
//            if(miroServiceEntities!=null && miroServiceEntities.size()>0){
//                for(int i=0;i<miroServiceEntities.size();i++){
//                    int j=mapper.deleteMiroservice(miroServiceEntities.get(i).getId());
//                    if(j==1){
//                        dao++;
//                    }
//                }
//
//            }else{
//                return 0;
//            }
        } catch (SQLException e) {
            System.out.println("***删除报错："+miroServiceEntity.getId()+"************");
            e.printStackTrace();
        }
        return dao;
    }




}
